import pandas as pd
import numpy as np

# 001
courses = ["语文", "数学", "英语", "计算机"]  # list
print(pd.Series(courses))  # 索引为默认的数字
print('\n')
# 002
grades = {"语文": 80, "数学": 90, "英语": 85, "计算机": 100}  # dict
print(pd.Series(grades))  # 参数字典(dict)时，索引为dict的key
print('\n')
# 003
data_1 = pd.Series(data=grades)
numbers = data_1.tolist()  #tolist() 是 Pandas 的 Series 对象中的一个方法，用于将 Series 转换为 Python 的列表
print(numbers)
print('\n')

# 004
data_2 = pd.DataFrame(data_1, columns=['grade'])
print(data_2);
print('\n')
# 005
data_3 = pd.Series(
    data=np.arange(10, 100, 10),  # 数值为10~90  间隔为10
    index=np.arange(101, 110),  # 索引为101~110
    dtype='float64'  # 类型为 float 64
)
print(data_3);
print('\n')
# 006
data_4 = pd.Series(
    data=["001", "002", "003", "004"],
    index=list("abcd")
)
print(data_4)
print(data_4.astype(int))
print(data_4.map(int))  # 这里的int是一个函数
print('\n')
# 007
data_1.loc['物理'] = 90  # Series中新增加索引
data_1.loc['化学'] = 90
print(data_1)
# 008
